import time

from selenium.webdriver.common.by import By
from Base.Base import Base

class Page(Base):
    search_loc = (By.XPATH,'//*[@id="stb"]')
    def search(self):
        return self.text(self.search_loc)

    sou_loc = (By.ID,'query')
    def sou(self):
        self.send_keys(self.sou_loc,'软件测试自动化')
        return self.text(self.sou_loc)

    def cl(self):
        self.click(self.search_loc)

    title_bt_loc = (By.ID,'promotion_adv_container')
    def title_bt(self):
        return self.text(self.title_bt_loc)

    next_page_loc = (By.XPATH,'//*[@id="sogou_next"]')
    def next_page(self):
        self.click(self.next_page_loc)
        print('---第二页----')

    title_next_lco = (By.CLASS_NAME,'results')
    def title_next(self):
        return self.text(self.title_next_lco)


    def sogou_01(self):
        self.open_url('https://www.sogou.com/')
        print(self.search())
        try:
            assert self.search() == '搜索'
        except Exception as e:
            print(e)
        time.sleep(3)
        self.sou()
        try:
            assert self.sou() == '软件测试自动化'
        except Exception as e:
            print(e)
        time.sleep(5)
        self.cl()
        time.sleep(5)
        print(self.title_bt())
        try:
            assert '软件测试' in self.title_bt()
        except Exception as e:
            print(e)
        time.sleep(5)
        self.next_page()
        print(self.title_next())
        try:
            assert '软件测试' in self.title_next()
        except Exception as e:
            print(e)